//package org.ricks.action.rpc;
//
//import org.ricks.net.action.context.session.TcpSessionAdapter;
//import org.ricks.net.action.rpc.RpcClient;
//import org.ricks.net.buffer.BufferPagePool;
//import org.ricks.net.enhance.EnhanceAsynchronousChannelProvider;
//import org.ricks.net.transport.AioQuickClient;
//import org.ricks.net.transport.AioSession;
//
//import java.io.IOException;
//import java.net.StandardSocketOptions;
//import java.nio.channels.AsynchronousChannelGroup;
//import java.util.ArrayList;
//import java.util.List;
//
//public class OptimizedRpcClient {
//    private static final BufferPagePool GLOBAL_POOL = new BufferPagePool(256 * 1024 * 1024, 8192);
//
//    public static void main(String[] args) throws IOException {
//        // 创建线程组 (8线程)
//        AsynchronousChannelGroup group = new EnhanceAsynchronousChannelProvider(false)
//                .openAsynchronousChannelGroup(8, Thread::new);
//
//        // 创建连接池 (4连接)
//        List<RpcClient> clients = new ArrayList<>();
//        for (int i = 0; i < 4; i++) {
//            AioQuickClient client = new AioQuickClient("localhost", 8888, new RpcProtocol(), new RpcHandler());
//            client.setReadBufferSize(64 * 1024)
//                    .setWriteBuffer(64 * 1024, 4096) // 64KB/块, 总容量256MB
//                    .setOption(StandardSocketOptions.SO_SNDBUF, 256 * 1024)
//                    .setOption(StandardSocketOptions.SO_RCVBUF, 256 * 1024)
//                    .disableLowMemory()
//                    .setBufferPagePool(GLOBAL_POOL);
//
//            AioSession session = client.start(group);
//            clients.add(new RpcClient(new TcpSessionAdapter(session), ...));
//        }
//
//        // 批处理请求 (100请求/批)
//        ExecutorService sender = Executors.newFixedThreadPool(16);
//        for (int i = 0; i < 100_000; i += 100) {
//            List<CompletableFuture<?>> batch = new ArrayList<>();
//            for (int j = 0; j < 100; j++) {
//                RpcClient client = clients.get((i + j) % clients.size());
//                batch.add(sender.submit(() -> client.invoke(...)));
//            }
//            CompletableFuture.allOf(batch.toArray(new CompletableFuture[0])).join();
//        }
//    }
//}